import { defineComponent } from "vue";
import MachineSelect from "./machineSelect";
export default defineComponent({
	props: {
		// todo: 需要改造成v-model
		detail: {
			type: Object,
			default() {
				return {};
			}
		},
		gatewayKey: {
			type: String,
			default() {
				return "gatewaySn";
			}
		}
	},
	emits: ["update:value"],
	setup(props, { emit }) {
		onMounted(async () => {});
		const drawerVisible = ref(false);
		const userSelect = (val: any) => {
			emit("update:value", val && val[0].sn);
			props.detail[props.gatewayKey] = val && val[0].sn;
		};
		return () => {
			return (
				<div>
					<MachineSelect
						v-model:visible={drawerVisible.value}
						onSubmit={userSelect}
						selectDefault={props.detail[props.gatewayKey] ? [props.detail[props.gatewayKey]] : undefined}
					></MachineSelect>
					<el-select
						v-model={props.detail[props.gatewayKey]}
						placeholder="请选择网关"
						value-key="id"
						onFocus={() => {
							drawerVisible.value = true;
						}}
					></el-select>
				</div>
			);
		};
	}
});
